const utils = require('../../../../common/util/util')
Page({
    data: {
        writed : []
    },
    onLoad: function (options) {
      options.type !== 'pain' ? this.xInit() :this.xInitPain()
      wx.setNavigationBarTitle({
        title: options.type !== 'pain' ? '我的日记' :'疼痛记录'
      })
    },
    // 疼痛日记
    xInitPain:function(){
      let that = this
      wx.cloud.callFunction({
        name: 'digital_therapy_extend',
        data: {
            action: "get_pain_diary_list"
        }
      }).then(res => {
          that.setData({
            writed : res.result
          })
      })
    },
    // 日记
    xInit: function () {
      let that = this
      wx.cloud.callFunction({
          name: 'digital_therapy',
          data: {
              action: "get_journal_List"
          }
      }).then(res => {
          let data = res.result
          for(var i in data){
              data[i].create_time = utils.formatTime_chinese(new Date(data[i].create_time))
          }
          that.setData({
            writed : data
          })
          
      })
    },
    xTodetails:function(e){
       let i= e.currentTarget.dataset.index;
       let datas = this.data.writed[i];
       wx.navigateTo({
         url: '../dayrembdetail/index?datas='+JSON.stringify(datas),
       })
    }
})